package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @Program: health_parent
 * @Description:
 * @Author: choulan
 * @Date:2020-11-11 17:04
 **/
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
        //获得redis数据库中两个集合的差值
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(set!=null){
            //删除七牛云上的图片
            for (String picName : set) {
                QiniuUtils.deleteFileFromQiniu(picName);
                //将redis中的垃圾图片删除
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,picName);
                System.out.println("清理垃圾图片任务执行...."+picName);
            }
        }
    }


}
